#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "process.h"
#define BUFFER_SIZE 100
#define MAX_RATE 100
#define STYLE '-'

const char  str[] = "|\\-/";
void process()
{
    //version 1
    int rate = 0;
    char buffer[BUFFER_SIZE+1] = {0};
    int strCount = 0;
    while(rate<=MAX_RATE)
    {
        strCount%=sizeof(str)-1;
        printf("[%-100s][%d%%][%c]\r",buffer,rate,str[strCount++]);
        fflush(stdout);
        usleep(1000*100*5);
        buffer[rate++] = STYLE;
    }
    printf("\n");
    return ;
}



    void process_ver1(int rate)
  {
      //version 2
      static  char buffer[BUFFER_SIZE+1] = {0};
      static int strCount = 0;
      if(rate<=MAX_RATE && rate>= 0)
      {
           strCount%=sizeof(str)-1;
          printf("[%-100s][%d%%][%c]\r",buffer,rate,str[strCount++]);
          fflush(stdout);
          buffer[rate++] = STYLE;
      }
      return ;
  }
  
